package com.zwan.oam_rtc.utils;

/**
 * Created by ZD on 2017/6/20.
 */
public class CapsCounter {
    private long count;
    private long lastCount;
    private long startTime;
    private long curTime;

    public CapsCounter(){
        count=0;
        lastCount=0;
    }

    public void tick(){
        if(count==0){
            startTime = System.currentTimeMillis();
        }
        curTime = System.currentTimeMillis();
        long l = curTime - startTime;

        if(l<=1000){
            count++;
        }else{
            lastCount = count;
            count = 0;
        }
    }

    public long getCaps(){
        long cur = System.currentTimeMillis();
        if(cur-curTime>2000){
            return 0;
        }
        return lastCount;
    }
}
